GIN_MODE := release
PORT_NUM := $(shell lsof -i | grep 8765 | awk -F ' ' '{print $$2}')
SEG_PORT_NUM := $(shell lsof -i | grep 8998 | awk -F ' ' '{print $$2}')
LAP_PORT_NUM := $(shell lsof -i | grep 8997 | awk -F ' ' '{print $$2}')
DEPLOY := /root/bgmp-deploy
SEG := /root/seg_rec_code
LAP := /root/lap-depth
CONDA_ACTIVATE=source /root/miniconda3/etc/profile.d/conda.sh ; conda activate ; conda activate

run: FORCE
ifneq ($(PORT_NUM),)
	kill -9 $(PORT_NUM)
endif
	go build
	mv bgmp $(DEPLOY)
	cp config.yaml $(DEPLOY)
	export GIN_MODE=$(GIN_MODE);cd ${DEPLOY};./bgmp > gin.log &

seg:
ifneq ($(SEG_PORT_NUM),)
	kill -9 $(SEG_PORT_NUM)
endif
	bash -c '$(CONDA_ACTIVATE) seg;cd ${SEG};python backend.py > seg.log 2>&1 &'

lap:
ifneq ($(LAP_PORT_NUM),)
	kill -9 $(LAP_PORT_NUM)
endif
	bash -c '$(CONDA_ACTIVATE) ld;cd ${LAP};python backend.py > lap.log 2>&1 &'

FORCE:
